package org.wisdom.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wisdom.entity.Order;
import org.wisdom.request.PostOrderRequest;
import org.wisdom.response.Result;
import org.wisdom.service.OrderService;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     */
    @PostMapping
    public Result<?> postOrder(@ModelAttribute PostOrderRequest postOrderRequest) throws IOException {
        orderService.postOrder(postOrderRequest);
        return Result.success();
    }

    /**
     * 获取单个订单的信息
     */
    @GetMapping("/{id}")
    public Result<Order> getOrder(@PathVariable Long id) {
        return Result.success(orderService.getOrder(id));
    }

    /**
     * 获取自己的购买订单
     */
    @GetMapping("/buy")
    public Result<List<Order>> getBuyOrder() {
        return Result.success(orderService.getBuyOrder());
    }

    /**
     * 获取自己的售卖订单
     */
    @GetMapping("/sell")
    public Result<List<Order>> getSellOrder() {
        return Result.success(orderService.getSellOrder());
    }

    /**
     * 获取公共的所有订单
     */
    @GetMapping("/public/all")
    public Result<List<Order>> getPublicOrder() {
        return Result.success(orderService.getPublicAllOrder());
    }

    /**
     * 获取公共的购买订单
     */
    @GetMapping("/public/buy")
    public Result<List<Order>> getPublicBuyOrder() {
        return Result.success(orderService.getPublicBuyOrder());
    }

    /**
     * 获取公共的售卖订单
     */
    @GetMapping("/public/sell")
    public Result<List<Order>> getPublicSellOrder() {
        return Result.success(orderService.getPublicSellOrder());
    }


}
